package com.prs.crm.action.sys;

import java.io.File;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.sys.LOGOSet;
import com.prs.crm.service.sys.LOGOSetService;

public class LOGOSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private LOGOSet logoSet;
	private LOGOSetService logoSetService;
	private File upload;
	private String uploadFileName;
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public LOGOSet getLogoSet() {
		return logoSet;
	}
	public void setLogoSet(LOGOSet logoSet) {
		this.logoSet = logoSet;
	}
	public LOGOSetService getLogoSetService() {
		return logoSetService;
	}
	public void setLogoSetService(LOGOSetService logoSetService) {
		this.logoSetService = logoSetService;
	}
	@Action("editLOGOSet")
	public String editLOGOSet(){
		return SUCCESS;
	}
	@Action(value="saveLOGOSet",results={
			@Result(name="success",type="redirect",location="editLOGOSet?logoSet=${logoSet.getId()}"),
			@Result(name="error",type="chain",location="editLOGOSet?logoSet=${logoSet.getId()}")
	})
	public String saveLOGOSet(){
		if(upload!=null){
			this.logoSet.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.getLogoSetService().save(logoSet);
		return SUCCESS;
	}
}
